/*
 * @Description: File Description
 * @Author: Bo.LiBo@bshg.com
 * @version: H3.0
 * @Date: 2023-03-13 11:34:27
 * @LastEditTime: 2023-04-07 15:09:37
 */
import type { ApplianceData } from "@/types/appliance";

/**
 * 修改时间字符串
 * @param 字符串，格式为 "yyyy-mm-dd HH:MM:SS"
 * @return 字符串，格式为 "HH:MM"
 */
export function getTimeStr(finishInAbsolute: string) {
  let timeStr = '';
  if (finishInAbsolute == null) {
    timeStr = 'null';
  } else {
    if (finishInAbsolute.indexOf(' ') != -1) {
      let time = finishInAbsolute.split(' ')[1];
      timeStr = time.slice(0, 5);
    }
  }
  return timeStr;
}

/**
 * 抑菌储存
 */
export function bacteriostaticStorage(item: ApplianceData) {
  let storageActiveTime = item.storageActiveTimeValue as unknown as number;
  if (!storageActiveTime) {
    item.storageActiveTimeValue = '';
  } else {
    if (storageActiveTime <= 60) {
      item.storageActiveTimeValue = '';
    } else if (storageActiveTime < 345600) {
      item.storageActiveTimeValue = '已抑菌储存' + '：' + formatHourMinute(storageActiveTime);
    } else {
      item.storageActiveTimeValue = '抑菌储存中';
    }
  }
}

/**
 * 秒数转化为时分秒
 */
export function formatHourMinute(value: number) {
  var secondTime = value; // 秒
  var minuteTime = 0; // 分
  var hourTime = 0; // 小时
  if (secondTime > 59) {
    minuteTime = Math.floor(secondTime / 60);
    secondTime = Math.floor(secondTime % 60);
    if (minuteTime > 59) {
      hourTime = Math.floor(minuteTime / 60);
      minuteTime = Math.floor(minuteTime % 60);
    }
  }
  var result = '';
  if (minuteTime > 0) {
    result = "" + minuteTime + '分钟' + result;
  }
  if (hourTime > 0) {
    result = "" + hourTime + '小时' + result;
  }
  return result;
}
